package com.smart4j.framework.thread.impl;

import com.smart4j.framework.thread.Sequence;

/**
 * description: SequenceB 线程之间变量 不进行共享 。
 * @version v1.0
 * @author w
 * @date 2018年10月10日下午10:19:46
 */
public class SequenceB implements Sequence {
	
	private static ThreadLocal<Integer> numberContainer = new ThreadLocal<Integer>() {
		@Override
		protected Integer initialValue() {
			return 0 ;
		};
	};
	
	@Override
	public int getNumber() {
		numberContainer.set(numberContainer.get() + 1);
		return numberContainer.get();
	}

	public static void main(String[] args) {
		Sequence sequence = new SequenceB();
		ClientThread thread1 = new ClientThread(sequence);
		ClientThread thread2 = new ClientThread(sequence);
		ClientThread thread3 = new ClientThread(sequence);
		
		numberContainer.remove();
		thread1.start();
		thread2.start();
		thread3.start();
	}
	
}
